package com.dbqn.zhao.service.impl;

import com.dbqn.zhao.entity.Novel;
import com.dbqn.zhao.service.BaseService;

import java.io.File;
import java.util.List;
import java.util.Scanner;

public class SwordsmanImpl implements BaseService {

    Scanner sc=new Scanner(System.in);
    @Override
    public List execute(List list) {

        System.out.println("---------------------------武侠小说列表开始------------------------");
        System.out.println("序号\t名称\t作者\t简介");

        for (int i = 0; i < list.size(); i++) {

            Novel novel1=(Novel) list.get(i);
            System.out.println((i+1)+novel1.getBookname()+"\t"+novel1.getName()+"\t"+novel1.getJianjie());
        }
        System.out.println("---------------------------小说列表结束------------------------");
        System.out.println("0.返回上一级菜单");
        System.out.println("-1.返回上一级菜单");
        System.out.println("请输入小说序号阅读");
        int shuuru=sc.nextInt();

        if(shuuru==0){
            return null;
        }else if(shuuru==-1){

            System.out.println("请输入小说名称:");
            String bookname=sc.next();
            System.out.println("请输入作者:");
            String name=sc.next();
            System.out.println("请输入简介:");
            String jianjie=sc.next();
            for(;;){

                System.out.println("请输入上传的txt(请注意路径用/或\\):");
                String luj=sc.next();

                File file=new File(luj);


                if(!file.exists()){
                    System.out.println("路径不存在，请重新上传");
                    continue;
                }


                Novel nover3=new Novel();
                nover3.setBookname(bookname);
                nover3.setName(name);
                nover3.setJianjie(jianjie);

                list.add(nover3);
                System.out.println("添加成功！");
                for (int i = 0; i < list.size(); i++) {

                    Novel novel1=(Novel) list.get(i);
                    System.out.println((i+1)+novel1.getBookname()+"\t"+novel1.getName()+"\t"+novel1.getJianjie());
                }
                System.out.println("************************");
                System.out.println("0.返回上一级菜单");
                System.out.println("1.继续上传");
                int xz=sc.nextInt();
                if(xz==0){
                    return null;
                }else{
                    continue;
                }

            }


        }


        return list;


    }
}
